#!/usr/bin/env python
#coding=utf-8

from aladin.database import db

class SysCategory(db.Model):
    __tablename__ = 'sys_category'

    cat_id   = db.Column(db.Integer, primary_key=True)
    cat_pid  = db.Column(db.Integer, default=0)
    cat_name = db.Column(db.String(32), default='')
    cat_desc = db.Column(db.String(255), default='')
    cat_img  = db.Column(db.String(255), default='')
    cat_type = db.Column(db.Integer, default=0)

    def __str__(self):
        return "SysCategory => { \
cat_id:%d, cat_pid:%d, cat_name:'%s', cat_desc:'%s', cat_img:'%s'}" % (
self.cat_id, self.cat_pid, self.cat_name, self.cat_desc, self.cat_img)

    __repr__ = __str__

    @staticmethod
    def get_category_select(cat_type=0):
        """获取分类select"""
        cat_list = SysCategory.query.filter(SysCategory.cat_pid == 0).\
                        filter(SysCategory.cat_type == cat_type).all()
        cat_arr = [{'name':c.cat_name, 'value':c.cat_id.__str__()} for c in cat_list]
        cat_arr.insert(0, {'name':u'请选择……', 'value':''})
        return cat_arr
        
